package com.intellagric.controller.module.sys_dictionary;

import com.intellagric.common.pojo.LayuiDataGridResult;
import com.intellagric.common.pojo.ResponseMessage;
import com.intellagric.pojo.SysDictionary;
import com.intellagric.service.module.sys_dictionary.DictionaryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;
import java.util.UUID;

/**
 * @Author: zhy
 * @email: 1269679946@qq.com
 * @Date: 2018/10/30
 * @DESC： 数据字典管理
 */
@Controller
public class DictionaryController {

    @Autowired
    private DictionaryService dictionaryService;

    /**
     * 添加数据字典信息
     * @Param dictionary
     * @return ResponseMessage
     */
    @RequestMapping("/dictionary/add")
    @ResponseBody
    public ResponseMessage add(SysDictionary dictionary) {
        dictionary.setId(UUID.randomUUID().toString().replaceAll("-",""));
        return dictionaryService.addDictionary(dictionary);
    }


    /**
     * 删除数据字典信息
     * @Param id
     * @return ResponseMessage
     */
    @RequestMapping("/dictionary/delete")
    @ResponseBody
    public ResponseMessage delete(String id) {
        return dictionaryService.deleteDictionary(id);
    }

    /**
     * 修改数据字典信息
     * @Param dictionary
     * @return ResponseMessage
     */
    @RequestMapping("/dictionary/edit")
    @ResponseBody
    public ResponseMessage edit(SysDictionary dictionary) {
        return dictionaryService.editDictionary(dictionary);
    }

    /**
     * 查询数据字典信息
     * @return SysDictionary
     */
    @RequestMapping("/dictionary/{id}")
    @ResponseBody
    public SysDictionary get(@PathVariable String id) {
        return dictionaryService.getDictionaryById(id);
    }

    /**
     * 查询数据字典树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/dictionary/tree")
    @ResponseBody
    public LayuiDataGridResult getTree() {
        return dictionaryService.getDictionaryTree();
    }

    /**
     * 查询数据字典树信息
     * @return LayuiDataGridResult
     */
    @RequestMapping("/dictionary/tree/select")
    @ResponseBody
    public List<SysDictionary> getTreeSelect() {
        return dictionaryService.getDictionaryTree().getData();
    }

    /**
     * 通过parentId查询数据字典信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/dictionary/list/{parentId}")
    @ResponseBody
    public LayuiDataGridResult getListByParentId(@PathVariable("parentId") String parentId) {
        return dictionaryService.getDictionaryByParentId(parentId);
    }

    /**
     * 查询数据字典信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/dictionary/list")
    @ResponseBody
    public LayuiDataGridResult getList() {
        return dictionaryService.getDictionaryList();
    }

    /**
     * 分页查询数据字典信息列表
     * @return LayuiDataGridResult
     */
    @RequestMapping("/dictionary/page")
    @ResponseBody
    public LayuiDataGridResult getPage() {
        return null;
    }

}
